<?php

namespace App\Admin\Controllers;

use App\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class UserController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '客服管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new User);
        // 搜索
        $grid->filter(function($filter){
            $filter->like('name', '昵称');

        });
        // 屏蔽操作
        $grid->disableRowSelector();

        // 操作栏
        $grid->actions(function ($actions) {
            // 去掉编辑
            $actions->disableEdit();

            // 去掉查看
            $actions->disableView();
        });
        $grid->column('id', __('ID'));
        $grid->column('name', __('昵称'));
        $grid->column('email', __('邮箱'));
        $grid->column('created_at', __('创建时间'));

        return $grid;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new User);
        $form->footer(function ($footer) {
            // 去掉`查看`checkbox
            $footer->disableViewCheck();
        });

        $form->text('name', __('昵称'));
        $form->email('email', __('邮箱'));
        $form->password('password', __('密码'));
        $form->saving(function (Form $form) {
            $form->password=bcrypt($form->password);
        });
        return $form;
    }
}
